
/**
 * Phone Tracker 3D Visualizer
 * August,2010
 * Capstone@jonathanleang.com
 * 
 * Phone Tracker 3D visualizer is a Phone Tracker visualiztion tool. 
 */
 
/* 
TODO 
make hover change to show or change color and make clear
Make click action to show the m  ore info
*/


import processing.video.*;
import processing.opengl.*;
import toxi.processing.*;
import toxi.geom.*;
import peasy.*;

ToxiclibsSupport gfx;

World world;
int tick;
int depth; // Z depth;

ScreenInfo screenInfo;
PApplet ptvPApplet;
Gateway ptvSniffers;
Vfilter ptvFilter;
Mapping ptvMapping;
Model model;

PeasyCam cam;
int FLOOR_NUM = 3; //using xml reader now
int FLOOR_HEIGHT = (screen.height/FLOOR_NUM)/2; // used in world 
int SNIFFER_SIZE = 25;
XMLReader xml;


void setup() {
  // xml load floor map, used in World
  xml = new XMLReader(this);
  ptvPApplet = this;
  
  // Setup
  hint(ENABLE_NATIVE_FONTS); 
  smooth();
  frameRate(30);
  
  //ptvSniffers = new BeASniffer(30, 300); // how many fake sniffers ? sniffers, nodes
  ptvSniffers = new Gateway(this);
  
  // Visuialation pipeline
  ptvFilter = new Vfilter(ptvSniffers.getSniffers(),ptvSniffers.getNodes());
  ptvMapping = new Mapping(ptvFilter.getSniffers(),ptvFilter.getNodes());
  
  tick = 0;
  gfx=new ToxiclibsSupport(this);
  //Setup the display window
  size(screen.width/2,screen.height/2,OPENGL);
  //World = the ground
  world = new World(ptvMapping.getSniffers(), ptvMapping.getNodes());
  //On screen Display
  screenInfo = new ScreenInfo();

  // Camera Control
  cam = new PeasyCam(this,width/2,height/2,height/4, 800);
  cam.setMinimumDistance(500);
  cam.setMaximumDistance(1500);
  
  // GUI ControlP5
  controlP5 = new ControlP5(this);
  controlP5.setAutoDraw(false);
  //PFont font = loadFont("Verdana-9.vlw"); 
  PFont font = createFont("SansSerif", 10); 
  controlP5.setControlFont(font);           // this fix the button color
  textFont(font,10); 
}


void draw() {
  ptvSniffers.draw();
  ptvMapping.draw();
  // Let there be light, default ambient and directional light
  lights();
  ambientLight(200, 200, 200);
  background(50);
  screenInfo.draw();
  pushMatrix();
  tick+=3;
  world.draw();
  popMatrix();

  // HUD
  cam.beginHUD();
  
  stroke(255);
  // ControlP5
  if (enter == true) {
    cam.setDistance(dx);
    searchbox();
  }
  // Screen Info
  oneScreenText();
  controlP5.draw();
  cam.endHUD();
}

